package project.innovation.mooddiagnosis.controller;

import lombok.extern.slf4j.Slf4j;
import org.python.antlr.ast.Str;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import project.innovation.mooddiagnosis.dto.result.ScaleRequest;
import project.innovation.mooddiagnosis.entity.image.ImageInfo;
import project.innovation.mooddiagnosis.entity.records.RecordInfo;
import project.innovation.mooddiagnosis.entity.result.Result;
import project.innovation.mooddiagnosis.entity.scaleScore.ScaleScore;
import project.innovation.mooddiagnosis.service.ResultService;

import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/result")
public class ResultController {
    @Autowired
    private ResultService resultService;

    Logger logger = LoggerFactory.getLogger(ResultController.class);

    /**
     * 返回用户多模态情感分析结果
     * @param map request body 需要userId
     * @return list<RecordInfo>
     */
    @RequestMapping("/list")
    public Result list(@RequestBody Map<String, String> map){
        String userId = map.get("userId");
        List<RecordInfo> list = resultService.selectRecordsByUserId(userId);
        return new Result(200, "用户记录列表查询成功", list);
    }

    /**
     * 删除历史记录
     * @param map request body 需要recordId
     * @return Result
     */
    @RequestMapping("/delete")
    public Result delete(@RequestBody Map<String, String> map){
        Integer recordId = Integer.parseInt(map.get("recordId"));
        int ret = resultService.deleteRecordById(recordId);
        return new Result(200, "记录删除成功", ret);
    }

    /**
     * 得到对应视频的特征图片
     * @param map request body 需要videoId
     * @return List<ImageInfo>
     * @throws FileNotFoundException
     */
    @RequestMapping("/images")
    public Result images(@RequestBody Map<String, String> map) throws FileNotFoundException {
        String videoId = map.get("videoId");
        List<ImageInfo> list = resultService.selectImagesByVideoId(videoId);
        return new Result(200, "特征图片查询成功", list);
    }

    /**
     * 量表数据计算得到RARS分析输入数据
     * @param request request body ScaleRequest
     * @return ScaleScore
     */
    @RequestMapping("/scale")
    public Result scale(@RequestBody ScaleRequest request) {
        logger.info("scale request: {}", request);
        return new Result(200,"分数计算成功", resultService.calculateScaleScore(request));
    }

    /**
     * 得到RARS分析结果
     * @param score request body ScaleScore
     * @return List<String>
     */
    @RequestMapping("/analyze")
    public Result analyze(@RequestBody ScaleScore score) {
        logger.info("analyze score: {}", score);
        return new Result(200, "分析结果获得成功", resultService.analyze(score));
    }

    /**
     * 得到用户RARS分析输入数据历史记录
     * @param map request body userId
     * @return list<ScaleScore>
     */
    @RequestMapping("/scalelist")
    public Result scalelist(@RequestBody Map<String, String> map) {
        String userId = map.get("userId");
        logger.info("scalelist request: {}", userId);
        List<ScaleScore> list = resultService.selectScaleScore(userId);
        return new Result(200, "量表分数计算成功", list);
    }
}
